<div class="box"> <!-- Box begins here -->
	<h2>Thêm menu</h2>
	<!--
	Standard form within a fieldset tag;
-->
	<?php 
		$error = $this->error;
		$data = $this->data;
	?>
<form method="post" action="" enctype="multipart/form-data"><!-- Form -->
				<?php 
					if(isset($this->success)){
						echo "<div class='success'><center><h3>".$this->success."</h3></center></div>";					
					}
				?>
					<fieldset><legend>Thông tin menu</legend>
					<div class="input_field">
						<label for="name">Tên menu</label>
 												
 						<?php echo $this->formText("name",$data['name'],null); ?>
 						<?php 
 							if(isset($error['name'])){
							echo '<span class="validate_error">'.$error['name'].'</span>';
							}
 						?>
					</div>
					<div class="input_field">
						<label for="link">Đường dẫn</label>
 												
 						<?php echo $this->formText("link",$data['link'],null); ?>
					</div>
					<div class="input_field">
						<label for="ordering">Thứ tự</label>
 												
 						<?php echo $this->formText("ordering",$data['ordering'],null); ?>
 						<?php 
 							if(isset($error['ordering'])){
							echo '<span class="validate_error">'.$error['ordering'].'</span>';
							}
 						?>
					</div>
					
					<div class="input_field">
							<label for="category">Thể loại menu</label>
	 						<select name="category" onchange="change_parent(this.options[this.selectedIndex].value);">
	 							<?php 
	 								$modelMenuCat = new Model_MenuCat_MenuCat();
	 								$menucat = $modelMenuCat->getAllIsActive();
	 								$i = 0;
	 								$first_id = '';
	 								foreach ($menucat as $item)
	 								{	
	 								    if($i==0)
	 								        $first_id = $item['id'];
	 								    $i++;
	 							?>					
	 									<option value="<?php echo $item['id'];?>" <?php if($data['category']==$item['id']) echo 'selected="selected"';?> ><?php echo $item['name'];?></option>
	 							<?php  }
	 							?>
	 							
	 						</select>
 					</div>
					
					<div id="input_parent" class="input_field">
							<label for="parent_id">Menu cha</label>
	 						<select name="parent_id" >
	 							<option value="0" >Không có</option>
	 							<?php 
	 								$modelMenu = new Model_Menu_Menu();
	 								$itemMenu = $modelMenu->getItemsByCate($first_id);
	 								foreach ($itemMenu as $item)
	 								{
	 									?>
	 									<option value="<?php echo $item['id'];?>"><?php echo $item['name'].' ('.$modelMenu->getNumbSub($item['id']).')';?></option>
	 							<?php }?>	 							
	 						</select>
 					</div>
					
					<div class="input_field">
							<label for="language">Ngôn ngữ </label>
	 						<select name="language" disabled="disabled">
	 							<?php 
	 								$modelLanguage = new Model_Language_Language();
	 								$language = $modelLanguage->getAll();
	 								foreach ($language as $item)
	 								{	
	 								    if($item['id']=='1')
	 								    {
	 							?>
	 							
	 							<option value="<?php echo $item['id'];?>" selected="selected" ><?php echo $item['name'];?></option>
	 							<?php } else {?>
	 							<option value="<?php echo $item['id'];?>" ><?php echo $item['name'];?></option>
	 							<?php } }?>
	 							
	 						</select>
 					</div>
					</fieldset>
					<fieldset><legend>Thông tin khác</legend>
					<div class="input_field">
						<label for="alt">Thuộc tính alt</label>				
 						<?php echo $this->formText("alt",$data['alt'],null); ?>
					</div>
					<div class="input_field">
						<label for="rel">Thuộc tính rel</label>				
 						<select name="rel">
 							<option value="" selected="selected" >Do follow</option>
 							<option value="nofollow">No follow</option>
 						</select>
					</div>
					<div class="input_field">
						<label for="title">Thuộc tính title</label>				
 						<?php echo $this->formText("title",$data['title'],null); ?>
					</div>
					<div class="input_field">
							<label for="status">Trạng thái</label>
 							<?php echo $this->formRadio("status",(empty($data['status'])) ? "1" : $data['status'],null,array("1"=>"Kích hoạt","0"=>"Không kích hoạt"),null); ?>
					</div>
					</fieldset>
					<input class="submit" type="submit" value="Lưu" />
			</form><!-- /Form -->
</div> <!-- END Box-->
<script>					
function change_parent(id){
	$("#input_parent").load("<?php echo $this->baseUrl()?>/administrator/ajax/menuparent/id/"+id);
}
</script>	 					